// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects;
using ValidationAspects.Exceptions;

namespace TestValidationAspects.Core
{
	[TestFixture]
	public class TestExceptionMessageFormatter
	{
		private const string _customMessage = "custom message";

		[SetUp]
		public void SetUp()
		{
			TestHelpers.ResetFramework();
		}

		[Test]
		public void Test_GreaterThan()
		{
			ValidationSettings.FormatExceptionMessage.GreaterThan(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateGreaterThanException.MessageFormat(new ValidateGreaterThanException(1, 2)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_GreaterThan_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.GreaterThan(null);
		}

		[Test]
		public void Test_InRange()
		{
			ValidationSettings.FormatExceptionMessage.InRange(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateInRangeException.MessageFormat(new ValidateInRangeException(1, 2, 3)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_InRange_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.InRange(null);
		}

		[Test]
		public void Test_IsDate()
		{
			ValidationSettings.FormatExceptionMessage.IsDate(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateIsDateException.MessageFormat(new ValidateIsDateException("format", "value")));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_IsDate_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.IsDate(null);
		}

		[Test]
		public void Test_IsEmail()
		{
			ValidationSettings.FormatExceptionMessage.IsEmail(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateIsEmailException.MessageFormat(new ValidateIsEmailException("value")));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_IsEmail_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.IsEmail(null);
		}

		[Test]
		public void Test_LengthInRange()
		{
			ValidationSettings.FormatExceptionMessage.LengthInRange(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateLengthInRangeException.MessageFormat(new ValidateLengthInRangeException(1, 2, 3)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_LengthInRange_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.LengthInRange(null);
		}


		[Test]
		public void Test_LessThan()
		{
			ValidationSettings.FormatExceptionMessage.LessThan(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateLessThanException.MessageFormat(new ValidateLessThanException(1, 2)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_LessThan_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.LessThan(null);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_MatchesRegex_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.InRange(null);
		}

		[Test]
		public void Test_Maximum()
		{
			ValidationSettings.FormatExceptionMessage.Maximum(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateMaximumException.MessageFormat(new ValidateMaximumException(1, 2)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Maximum_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.Maximum(null);
		}

		[Test]
		public void Test_MaximumLength()
		{
			ValidationSettings.FormatExceptionMessage.MaximumLength(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateMaximumLengthException.MessageFormat(new ValidateMaximumLengthException(1, 2)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_MaximumLength_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.MaximumLength(null);
		}

		[Test]
		public void Test_Minimum()
		{
			ValidationSettings.FormatExceptionMessage.Minimum(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateMinimumException.MessageFormat(new ValidateMinimumException(1, 2)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Minimum_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.Minimum(null);
		}

		[Test]
		public void Test_MinimumLength()
		{
			ValidationSettings.FormatExceptionMessage.MinimumLength(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateMinimumLengthException.MessageFormat(new ValidateMinimumLengthException(1, 2)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_MinimumLength_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.MinimumLength(null);
		}

		[Test]
		public void Test_NotEqual()
		{
			ValidationSettings.FormatExceptionMessage.NotEqual(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateNotEqualException.MessageFormat(new ValidateNotEqualException(1)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_NotEqual_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.NotEqual(null);
		}

		[Test]
		public void Test_NotInRange()
		{
			ValidationSettings.FormatExceptionMessage.NotInRange(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateNotInRangeException.MessageFormat(new ValidateNotInRangeException(1, 2, 3)));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_NotInRange_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.NotInRange(null);
		}

		[Test]
		public void Test_NotNull()
		{
			ValidationSettings.FormatExceptionMessage.NotNull(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateNotNullException.MessageFormat(new ValidateNotNullException()));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_NotNull_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.NotNull(null);
		}

		[Test]
		public void Test_NotNullOrEmpty()
		{
			ValidationSettings.FormatExceptionMessage.NotNullOrEmpty(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateNotNullOrEmptyException.MessageFormat(new ValidateNotNullOrEmptyException()));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_NotNullOrEmpty_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.NotNullOrEmpty(null);
		}

		[Test]
		public void Test_ValidateObject()
		{
			ValidationSettings.FormatExceptionMessage.ValidateObject(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateObjectException.MessageFormat(new ValidateObjectException(new object())));
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_ValidateObject_throws_for_null_param()
		{
			ValidationSettings.FormatExceptionMessage.ValidateObject(null);
		}

		[Test]
		public void TestMatchesRegex()
		{
			ValidationSettings.FormatExceptionMessage.MatchesRegex(e => _customMessage);
			Assert.AreEqual(_customMessage, ValidateMatchesRegexException.MessageFormat(new ValidateMatchesRegexException("pattern", "value")));
		}
	}
}